GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( db4227...311fcc )
by Florian
01:18
created

Line.updateMarkerRemoved   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
nc 4
nop 1
dl 0
loc 15
rs 9.4285
c 1
b 0
f 0
1
/*jslint
2
  regexp: true
3
  indent: 4
4
*/
5
6
/*global
7
  $, google, theMarkers, id2alpha, Cookies, Coordinates, TxtOverlay
8
*/
9
10
function Line(themap, id, source, target) {
11
    'use strict';
12
13
    this.m_map = themap;
14
    this.m_id = id;
15
    this.m_lineMapObject = null;
16
    this.m_source = -1;
17
    this.m_target = -1;
18
    this.m_distanceLabel = null;
19
20
    $('#dynLineDiv').append(
21
        "<div id=\"dynLine" + id + "\">" +
22
            "<table style=\"width: 100%\">" +
23
            "<tr>" +
24
            "<td>" +
25
            "<select id=\"dynlinesource" + id + "\" class=\"my-small-select\" data-i18n=\"[title]sidebar.lines.source\" onchange=\"Lines.selectLineSource(" + id + ")\"><option value=\"-1\">?</option></select>" +
26
            "&nbsp;&rarr;&nbsp;" +
27
            "<select id=\"dynlinetarget" + id + "\" class=\"my-small-select\" data-i18n=\"[title]sidebar.lines.destination\" onchange=\"Lines.selectLineTarget(" + id + ")\"><option value=\"-1\">?</option></select>" +
28
            "</td>" +
29
            "<td>" +
30
            "<button class=\"my-button btn btn-mini btn-danger\" style=\"float: right\" data-i18n=\"[title]sidebar.lines.delete_line\" type=\"button\" onClick=\"trackLine('delete'); Lines.deleteLine(" + id + ")\"><i class=\"fa fa-trash-o\"></i></button>" +
31
            "<div>" +
32
            "</div>" +
33
            "</td>" +
34
            "</tr>" +
35
            "<tr><td colspan=\"2\"><i class=\"fa fa-arrows-h\"></i> <span id=\"dynlinedist" + id + "\">n/a</span> <i class=\"fa fa-compass\"></i> <span id=\"dynlineangle" + id + "\">n/a</span></td></tr>" +
36
            "</table>" +
37
            "</div>"
38
    );
39
40
    this.updateLists();
41
    this.setSource(source);
42
    this.setTarget(target);
43
}
44
45
46
Line.prototype.m_map = null;
47
Line.prototype.m_id = -1;
48
Line.prototype.m_lineMapObject = null;
49
Line.prototype.m_source = -1;
50
Line.prototype.m_target = -1;
51
Line.prototype.m_distanceLabel = null;
52
53
54
Line.prototype.getId = function () {
55
    'use strict';
56
57
    return this.m_id;
58
};
59
60
61
Line.prototype.clearMapObject = function () {
62
    'use strict';
63
64
    if (this.m_lineMapObject) {
65
        this.m_lineMapObject.setMap(null);
66
        this.m_lineMapObject = null;
67
    }
68
69
    if (this.m_distanceLabel) {
70
        this.m_distanceLabel.setMap(null);
71
        this.m_distanceLabel = null;
72
    }
73
};
74
75
76
Line.prototype.updateMapObject = function (pos1, pos2, center) {
77
    'use strict';
78
79
    if (!this.m_lineMapObject) {
80
        this.m_lineMapObject = new google.maps.Polyline({
81
            strokeColor: '#ff0000',
82
            strokeWeight: 2,
83
            strokeOpacity: 0.7,
84
            geodesic: true,
85
            icons: [{
86
                icon: {
87
                    path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW
88
                },
89
                repeat: '0'
90
            }]
91
        });
92
        this.m_lineMapObject.setMap(this.m_map);
93
        this.m_distanceLabel = new TxtOverlay(center, "n/a", "mapDistanceLabel", this.m_map);
94
    }
95
96
    var path = new google.maps.MVCArray();
97
    path.push(pos1);
98
    path.push(pos2);
99
    this.m_lineMapObject.setPath(path);
100
101
    this.m_distanceLabel.setPos(center);
102
};
103
104
105
Line.prototype.getEndpointsString = function () {
106
    'use strict';
107
108
    return id2alpha(this.m_source) + ":" + id2alpha(this.m_target);
109
};
110
111
112
Line.prototype.setSource = function (markerId) {
113
    'use strict';
114
115
    if (markerId !== this.m_source) {
116
        this.m_source = markerId;
117
        this.update();
118
        $("#dynlinesource" + this.m_id + " > option[value=" + markerId + "]").attr("selected", "selected");
119
    }
120
};
121
122
123
Line.prototype.setTarget = function (markerId) {
124
    'use strict';
125
126
    if (markerId !== this.m_target) {
127
        this.m_target = markerId;
128
        this.update();
129
        $("#dynlinetarget" + this.m_id + " > option[value=" + markerId + "]").attr("selected", "selected");
130
    }
131
};
132
133
134
Line.prototype.update = function () {
135
    'use strict';
136
137
    if (this.m_source === -1 || this.m_target === -1) {
138
        this.clearMapObject();
139
140
        $("#dynlinedist" + this.m_id).html("n/a");
141
        $("#dynlineangle" + this.m_id).html("n/a");
142
143
        return;
144
    }
145
146
    var pos1 = theMarkers.getById(this.m_source).getPosition(),
147
        pos2 = theMarkers.getById(this.m_target).getPosition(),
148
        dist_angle = Coordinates.dist_angle_geodesic(pos1, pos2),
149
        centerPos = Coordinates.projection_geodesic(pos1, dist_angle.angle, 0.5 * dist_angle.dist);
150
151
    this.updateMapObject(pos1, pos2, centerPos);
152
153
    if (dist_angle.dist <= 0) {
154
        this.m_distanceLabel.setText("");
155
        $("#dynlinedist" + this.m_id).html("0m");
156
        $("#dynlineangle" + this.m_id).html("n/a");
157
    } else {
158
        this.m_distanceLabel.setText(dist_angle.dist.toFixed() + "m");
159
        $("#dynlinedist" + this.m_id).html(dist_angle.dist.toFixed() + "m");
160
        $("#dynlineangle" + this.m_id).html(dist_angle.angle.toFixed(1) + "°");
161
    }
162
};
163
164
165
Line.prototype.updateMarkerMoved = function (markerId) {
166
    'use strict';
167
168
    if (this.m_source === markerId || this.m_target === markerId) {
169
        this.update();
170
    }
171
};
172
173
174
Line.prototype.updateMarkerRemoved = function (markerId) {
175
    'use strict';
176
177
    if (this.m_source === markerId) {
178
        this.m_source = -1;
179
        this.clearMapObject();
180
    }
181
182
    if (this.m_target === markerId) {
183
        this.m_target = -1;
184
        this.clearMapObject();
185
    }
186
187
    this.updateLists();
188
};
189
190
191
Line.prototype.updateMarkerAdded = function () {
192
    'use strict';
193
194
    this.updateLists();
195
};
196
197
198
Line.prototype.updateLists = function () {
199
    'use strict';
200
201
    var source = $('#dynlinesource' + this.m_id),
202
        target = $('#dynlinetarget' + this.m_id),
203
        i,
204
        m;
205
206
    source.empty();
207
    target.empty();
208
209
    source.append('<option value="-1">?</option>');
210
    target.append('<option value="-1">?</option>');
211
212
    for (i = 0; i < theMarkers.getSize(); i = i + 1) {
213
        m = theMarkers.getById(i);
214
        if (!m.isFree()) {
215
            source.append('<option value="' + i + '">' + m.getAlpha() + '</option>');
216
            target.append('<option value="' + i + '">' + m.getAlpha() + '</option>');
217
        }
218
    }
219
220
    $("#dynlinesource" + this.m_id + " > option[value=" + this.m_source + "]").attr("selected", "selected");
221
    $("#dynlinetarget" + this.m_id + " > option[value=" + this.m_target + "]").attr("selected", "selected");
222
};
223
224
225
var Lines = {};
226
Lines.m_map = null;
227
Lines.m_nextLineId = 0;
228
Lines.m_lines = [];
229
230
231
Lines.init = function (themap) {
232
    'use strict';
233
234
    Lines.m_map = themap;
235
    Lines.m_nextLineId = 0;
236
    Lines.m_lines = [];
237
};
238
239
240
Lines.newLine = function (source, target) {
241
    'use strict';
242
243
    this.m_lines.push(new Line(Lines.m_map, this.m_nextLineId, source, target));
244
    this.m_nextLineId += 1;
245
    this.saveCookie();
246
};
247
248
249
Lines.getLineIndex = function (id) {
250
    'use strict';
251
252
    var index, line;
253
254
    for (index = 0; index < this.m_lines.length; index += 1) {
255
        line = this.m_lines[index];
256
        if (line && line.getId() === id) {
257
            return index;
258
        }
259
    }
260
261
    return -1;
262
};
263
264
265
Lines.getLineById = function (id) {
266
    'use strict';
267
268
    var index = this.getLineIndex(id);
269
    if (index < 0) {
270
        return null;
271
    }
272
    return this.m_lines[index];
273
};
274
275
276
Lines.getLinesText = function () {
277
    'use strict';
278
279
    var a = [];
280
    this.m_lines.map(function (line) {
281
        if (line) {
282
            a.push(line.getEndpointsString());
283
        }
284
    });
285
    return a.join("*");
286
};
287
288
289
Lines.saveCookie = function () {
290
    'use strict';
291
292
    Cookies.set("lines", this.getLinesText(), {expires: 30});
293
};
294
295
296
Lines.selectLineSourceById = function (id, markerId) {
297
    'use strict';
298
299
    this.getLineById(id).setSource(markerId);
300
    this.saveCookie();
301
};
302
303
304
Lines.selectLineSource = function (id) {
305
    'use strict';
306
307
    var markerId = -1,
308
        opt = $("#dynlinesource" + id + " option:selected");
309
310
    if (opt) {
311
        markerId = parseInt(opt.val(), 10);
312
    }
313
314
    this.selectLineSourceById(id, markerId);
315
};
316
317
318
Lines.selectLineTargetById = function (id, markerId) {
319
    'use strict';
320
321
    this.getLineById(id).setTarget(markerId);
322
    this.saveCookie();
323
};
324
325
326
Lines.selectLineTarget = function (id) {
327
    'use strict';
328
329
    var markerId = -1,
330
        opt = $("#dynlinetarget" + id + " option:selected");
331
332
    if (opt) {
333
        markerId = parseInt(opt.val(), 10);
334
    }
335
336
    this.selectLineTargetById(id, markerId);
337
};
338
339
340
Lines.updateLinesMarkerMoved = function (markerId) {
341
    'use strict';
342
343
    this.m_lines.map(function (line) {
344
        if (line) {
345
            line.updateMarkerMoved(markerId);
346
        }
347
    });
348
};
349
350
351
Lines.updateLinesMarkerAdded = function () {
352
    'use strict';
353
354
    this.m_lines.map(function (line) {
355
        if (line) {
356
            line.updateMarkerAdded();
357
        }
358
    });
359
};
360
361
362
Lines.updateLinesMarkerRemoved = function (markerId) {
363
    'use strict';
364
365
    this.m_lines.map(function (line) {
366
        if (line) {
367
            line.updateMarkerRemoved(markerId);
368
        }
369
    });
370
    this.saveCookie();
371
};
372
373
374
Lines.updateLine = function (id) {
375
    'use strict';
376
377
    var index = this.getLineIndex(id);
378
    if (index < 0) {
379
        return;
380
    }
381
382
    this.m_lines[index].update();
383
};
384
385
386
Lines.deleteLine = function (id) {
387
    'use strict';
388
389
    $('#dynLine' + id).remove();
390
391
    var index = this.getLineIndex(id);
392
    if (index < 0 || !this.m_lines[index]) {
393
        return;
394
    }
395
396
    this.m_lines[index].clearMapObject();
397
    this.m_lines[index] = null;
398
399
    this.saveCookie();
400
};
401
402
403
Lines.deleteAllLines = function () {
404
    'use strict';
405
406
    var self = this;
407
    this.m_lines.map(function (line) {
408
        if (line) {
409
            self.deleteLine(line.getId());
410
        }
411
    });
412
};
413